<html>
<head>
    <title>修改</title>
</head>
<link rel="stylesheet" href="/static/layui/css/layui.css" />
<body>

<form class="layui-form"  action="" lay-filter="edit">
    <input type="hidden" name="reid">
    <div class="layui-form-item">
        <label class="layui-form-label">房屋名称：</label>
        <div class="layui-input-inline layui-col-md4">
            <select name="hid" id="hid" lay-verify="required">
                <option value="">-----请选择-----</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">后勤人员：</label>
        <div class="layui-input-inline layui-col-md4">
            <select name="loid" id="loid" lay-verify="required">
                <option value="">-----请选择-----</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注：</label>
        <div class="layui-input-inline layui-col-md4">
            <input type="tel" name="reremark" id="reremark" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <!--<div class="layui-form-item">
        <label class="layui-form-label">修缮时间：</label>
        <div class="layui-input-inline">
            <input type="tel" name="retime" id="retime" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>-->
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
        </div>
    </div>
</form>
</body>

<script src="/static/js/system.js"></script>
<script src="/static/js/jquery-3.3.1.js"></script>
<script src="/static/layui/layui.js"></script>
<script>
    //Demo

    layui.use(['form','layer'], function(){
        var form = layui.form;
        $.ajax({
            url:"/RecordServlet?method=QueryLoid",
            type:"post",
            // data:{},
            dataType:"json",
            async:false,
            success:function (res) {
                $.each(res.data,function (i,obj) {
                    // console.log("下拉列表loid："+obj);
                    $("#loid").append('<option value="'+obj.loid+'">'+obj.loname+'</option>');

                });
                form.render('select'); //刷新select选择框渲染
            }
        });
        $.ajax({
            url:"/RecordServlet?method=QueryHid",
            type:"post",
            // data:{},
            dataType:"json",
            async:false,
            success:function (res) {
                // console.log(res)
                $.each(res.data,function (i,obj) {
                    $("#hid").append('<option value="'+obj.hid+'">'+obj.hestate + obj.hunitNumber+obj.hroomNo+'</option>');
                });
                form.render('select'); //刷新select选择框渲染
            }
        });


        //单个查询，为修改做准备
        $.ajax({
            url:'/RecordServlet?method=ShowOne',
            type:"get",
            dataType:"json",
            data:{"reid":getQueryString("reid")},
            success:function (da) {
                if (da.code == 200) {
                    form.val("edit",da.data);
                    $("hid").find("option[value ="+da.hestate + da.hunitNumber+da.hroomNo+"]").prop("selected",true);
                    $("loid").find("option[value ="+da.loname+"]").prop("selected",true);
                    // $('#reremark').val(da.reremark);
                    // $('#retime').val(da.retime);
                    form.render("select");
                } else {
                    layer.msg("查询数据失败！");
                }
            }
        });




        //监听提交 15039939677
        form.on('submit(formDemo)', function(data){
            var data1 = form.val("edit");
            // console.log(data1);
            $.ajax({
                url:'/RecordServlet?method=Update',
                type:"post",
                dataType:"json",
                data:data1,
                success:function (da) {
                    if (da.code == 200) {
                        layer.alert("修改成功！", function () {
                            // window.parent.location.reload();//刷新父页面
                            // parent.layer.close(layer.index);//关闭弹出层
                            parent.layer.closeAll();
                        });
                    } else {
                        layer.msg("修改失败！");
                    }
                }
            });
            return false;
        });
    });
</script>
</html>
